/*
*
==============================================================================
*  Name        : 
*  Part of     : Omen Game Engine
*  Description : 
*  Version     : 1.0
*
*  Copyright (c) 2013 Lauri Kortevaara.
* 
==============================================================================
*/

#define OMEN_SOURCE 1

#include <OmenPlane.h>

using namespace Omen;

Plane::Plane( Omen::Float _a, Omen::Float _b, Omen::Float _c, Omen::Float _d) :
    a(_a),b(_b),c(_c),d(_d)
{
}

Plane::Plane( Omen::Vector3d normal, Omen::Vector3d p0 )
{
    a = normal.x; b = normal.y, c = normal.z;
    d = -Vector3d::dotProduct( normal, p0 );
}

/// <summary>Normalizes the plane so that |a,b,c| == 1</summary>
void Plane::normalize()
{
    Float len = static_cast<Omen::Float>(sqrt(a*a+b*b+c*c));
    if( len != 0.0 )
    {
        a /= len;
        b /= len;
        c /= len;
    }
}

/// <summary>Returns dot product of plane and point in 3d space</summary>
Omen::Float Plane::dotProduct( const Omen::Vector3d& point )
{
    return Vector3d::dotProduct( Vector3d(a,b,c), point );
}

/// EOF